package cn.stylefeng.guns.modular.business.common;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;


@Configuration
@EnableAsync
public class ThreadPoolTaskExecutorConfig {

    private final int corePoolSize;

    private final int maxPoolSize;

    private final int queueCapacity;

    public ThreadPoolTaskExecutorConfig() {
        queueCapacity = 500;
        maxPoolSize = 10;
        corePoolSize = 5;
    }

    @Bean
    public Executor asyncSendTemplateMessage() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setMaxPoolSize(maxPoolSize);
        executor.setQueueCapacity(queueCapacity);
        executor.setThreadNamePrefix("asyncSendTemplateMessage-");
        executor.initialize();
        return executor;
    }

    @Bean
    public Executor analyzeUserGradeAsync() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setMaxPoolSize(maxPoolSize);
        executor.setQueueCapacity(queueCapacity);
        executor.setThreadNamePrefix("analyzeUserGradeAsync-");
        executor.initialize();
        return executor;
    }
}
